package com.yihong.userserver.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * @ClassName User
 * @Description
 * @Author 孟志浩
 * @Date 2019/3/18 10:22
 **/
// 自动Getter、Setter
@Data
// 链式写法 user.setId(1).setName("user").setPassword("123");
@Accessors(chain = true)
// 无参构造
@NoArgsConstructor
// 标注是实体类
@Entity
// 数据库表名称
@Table(name = "t_user")
// 防止字段为null时查询失败
@JsonIgnoreProperties(value = {"hibernateLazyInitializer", "handler"})
public class User implements Serializable {

    /**
     *  用户编号
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 真实姓名
     */
    @Column(name = "name", length=50)
    private String name;

    /**
     *  登陆名称
     */
    @Column(name = "loginName", length=50, nullable = false)
    private String loginName;

    /**
     * 用户登陆密码
     */
    @Column(name = "password", length=50, nullable = false)
    private String password;

    /**
     * 手机号
     */
    @Column(name = "MobilePhone", length=50)
    private String MobilePhone;

    /**
     * 身份证号
     */
    @Column(name = "idCard", length=50)
    private String idCard;

    /**
     * 邮箱
     */
    @Column(name = "email", length=50)
    private String email;

    /**
     * 性别
     */
    @Column(name = "gender", length=50)
    private String gender;

    /**
     * 创建人
     */
    @Column(name = "creatorId", length = 100)
    private Long creatorId;

    /**
     * 创建时间
     */
    @Column(name = "createTime")
    private Date createTime;

    /**
     * 修改人编号
     */
    @Column(name = "modifierId")
    private Long modifierId;

    /**
     * 修改时间
     */
    @Column(name = "modifyTime")
    private Date modifyTime;

    /**
     * 最近一次登录时间
     */
    @Column(name = "lastLoginTime")
    private Date lastLoginTime;

    /**
     * 是否有效
     */
    @Column(name = "isValid", nullable = false, columnDefinition = "int default 1")
    private Integer isValid;

    /**
     * 用户类型(1:管理员 2:普通用户)
     */
    @Column(name = "userType")
    private Integer userType;

    /**
     *  一个用户对应多个角色
     */
    @ManyToMany(mappedBy = "userList")
    private List<Role> roleList;
}
